package org.dromara.business.modules.intro.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.business.modules.intro.domain.bo.BuIntroBo;
import org.dromara.business.modules.intro.domain.vo.BuIntroVo;
import org.dromara.business.modules.intro.service.IBuIntroService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务中心
 *
 * @author ckk
 * @date 2025-11-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/intro")
public class BuIntroController extends BaseController {

    private final IBuIntroService buIntroService;

    /**
     * 查询服务中心列表
     */
    @SaIgnore
    @GetMapping("/list")
    public TableDataInfo<BuIntroVo> list(BuIntroBo bo, PageQuery pageQuery) {
        return buIntroService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务中心列表
     */
    @SaCheckPermission("business:intro:export")
    @Log(title = "服务中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BuIntroBo bo, HttpServletResponse response) {
        List<BuIntroVo> list = buIntroService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务中心", BuIntroVo.class, response);
    }

    @SaIgnore
    @GetMapping("/{id}")
    public R<BuIntroVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(buIntroService.queryById(id));
    }

    /**
     * 新增服务中心
     */
    @SaCheckPermission("business:intro:add")
    @Log(title = "服务中心", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BuIntroBo bo) {
        return toAjax(buIntroService.insertByBo(bo));
    }

    /**
     * 修改服务中心
     */
    @SaCheckPermission("business:intro:edit")
    @Log(title = "服务中心", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BuIntroBo bo) {
        return toAjax(buIntroService.updateByBo(bo));
    }

    /**
     * 删除服务中心
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:intro:remove")
    @Log(title = "服务中心", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(buIntroService.deleteWithValidByIds(List.of(ids), true));
    }
}
